package com.n9.qqonline.sales.service;

import com.n9.db.util.GenericService;
import com.n9.qqonline.sales.entity.Config;

import java.util.Iterator;
import java.util.List;
import java.util.Objects;

/**
 * @author ice
 * @since 2019/3/19 15:05
 */
public class ConfigService {
    public Config getConfig() {
        List<Config> configs = new GenericService().queryAll("FROM Config");
        Iterator<Config> it = configs.iterator();
        return it.hasNext() ? it.next() : new Config();
    }

    public void saveOrUpdate(Config config) {
        GenericService genericService = new GenericService();
        if (Objects.isNull(config.getId())) {
            genericService.save(config);
        } else {
            genericService.update(config);
        }
    }

}
